import com.niit.springdemo001.dao.TestDao;
import com.niit.springdemo001.dao.impl.Custmor;
import com.niit.springdemo001.dao.impl.Question;
import com.niit.springdemo001.dao.impl.TestDaoImpl;
import org.junit.Test;
import org.springframework.beans.factory.BeanFactory;
import org.springframework.beans.factory.xml.XmlBeanFactory;
import org.springframework.context.annotation.Bean;
import org.springframework.core.io.ClassPathResource;
import org.springframework.core.io.Resource;

//使用setter进行依赖注入
public class springdemotest001 {
    @Test
    public void test01(){
        Resource resource = new ClassPathResource("applicationContext.xml");
//        创建bean工厂并加载xml资源
        BeanFactory beanFactory = new XmlBeanFactory(resource);

//        通过bean工厂获取bean并加载类文件
        TestDao testDao = beanFactory.getBean("testDao001", TestDaoImpl.class);
        testDao.test001();
        testDao.test002();

//        setter注入simple values
        Custmor custmor = beanFactory.getBean("bean0", Custmor.class);
        custmor.display();

//        ref注入引用对象
        Custmor custmor2 = beanFactory.getBean("bean2", Custmor.class);
        custmor2.display();


//         注入集合
        Question question = beanFactory.getBean("bean3", Question.class);
        question.display();

    }
}
